﻿using AutoMapper;
using MediatR;
using S_Gridding.Api.Application.Commands.Respon;
using S_Gridding.Api.Application.Commands.Teamgrid;
using S_Gridding.Domains.FoundGridding;
using S_Gridding.Infrastructure.Interface.IWrite;

namespace S_Gridding.Api.Application.CommandsHanders.TeamgridHanders
{
    public class TeamgridCreateCommandsHanders : IRequestHandler<TeamgridCreateCommands, int>
    {
        private readonly ITeamgridRepository teamgrid;
        private readonly IMapper _mapper;

        public TeamgridCreateCommandsHanders(ITeamgridRepository teamgrid, IMapper mapper)
        {
            this.teamgrid = teamgrid;
            _mapper = mapper;
        }

        public async Task<int> Handle(TeamgridCreateCommands request, CancellationToken cancellationToken)
        {
            var res = _mapper.Map<Teamgrid>(request);
            res.IsDel = false;
            return await teamgrid.AddAsync(res);
        }
    }
}
